httr::set_config(httr::config(http_version = 0))
library(ggmap)
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(ggplot2)
library(gridExtra)
ggmap(get_map(geocode("Canberra")))
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Canberra&key=xxx-TJHG3V6fT4FydpG8nZv_ehbN_Iw
## Source : https://maps.googleapis.com/maps/api/staticmap?center=-35.280937,149.130009&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-TJHG3V6fT4FydpG8nZv_ehbN_Iw

# enable Geocoding API,Maps Static API!!!
corvallis <- c(lon = -123.2620, lat = 44.5646)
# Get map at different zoom level :
map_5 <- get_map(corvallis, zoom = 5, scale = 1)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=44.5646,-123.262&zoom=5&size=640x640&scale=1&maptype=terrain&language=en-EN&key=xxx-TJHG3V6fT4FydpG8nZv_ehbN_Iw
ggmap(map_5)

corvallis_map <- get_map(corvallis,zoom=13,scale=1)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=44.5646,-123.262&zoom=13&size=640x640&scale=1&maptype=terrain&language=en-EN&key=xxx-TJHG3V6fT4FydpG8nZv_ehbN_Iw
ggmap(corvallis_map)

setwd("~/Desktop/Spatial Analysis")
sales<-readRDS("sales.rds")
head(sales)
## # A tibble: 6 x 20
## lon lat price finished_squaref… year_built date address city state
## <dbl> <dbl> <dbl> <int> <int> <date> <chr> <chr> <chr>
## 1 -123. 44.6 267500 1520 1967 2015-12-31 1112 N… CORV… OR
## 2 -123. 44.6 255000 1665 1990 2015-12-31 1221 N… CORV… OR
## 3 -123. 44.6 295000 1440 1948 2015-12-31 440 NW… CORV… OR
## 4 -123. 44.6 5000 784 1978 2015-12-31 2655 N… CORV… OR
## 5 -123. 44.5 13950 1344 1979 2015-12-31 300 SE… CORV… OR
## 6 -123. 44.6 233000 1567 2002 2015-12-30 3006 N… CORV… OR
## # … with 11 more variables: zip <chr>, acres <dbl>, num_dwellings <int>,
## # class <chr>, condition <chr>, total_squarefeet <int>, bedrooms <int>,
## # full_baths <int>, half_baths <int>, month <dbl>, address_city <chr>
ggmap(corvallis_map) +
geom_point(aes(lon, lat), data = sales)

# Map color to year_built
ggmap(corvallis_map) +
geom_point(aes(lon, lat, color = year_built), data = sales)

# Map color to price / finished_squarefeet
ggmap(corvallis_map) +
geom_point(
aes(lon, lat, color = price / finished_squarefeet),
data = sales
)

#satellite map
corvallis <- c(lon = -123.2620, lat = 44.5646)
corvallis_map_sat <- get_map(corvallis,maptype="satellite", zoom = 13)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=44.5646,-123.262&zoom=13&size=640x640&scale=2&maptype=satellite&language=en-EN&key=xxx-TJHG3V6fT4FydpG8nZv_ehbN_Iw
ggmap(corvallis_map_sat) +
geom_point(aes(lon, lat, color = year_built), data = sales)
